package com.tencreat.mall.controller.admin;

import java.util.List;

import com.tencreat.common.core.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.domain.mall.AppDownloadRecord;
import com.tencreat.service.mall.IAppDownloadRecordService;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * app下载记录Controller
 *
 * @author tencreat
 * @company: 深圳腾创互联科技有限公司
 * @link: https://tencreat.com
 * @date 2022-12-19
 */
@Api(tags = "app下载记录api")
@RestController
@RequestMapping("/mall/appDownloadRecord")
@RequiredArgsConstructor
public class AppDownloadRecordController extends BaseController {

    private final IAppDownloadRecordService appDownloadRecordService;

    /**
    * 查询app下载记录列表
    */
    @ApiOperation(value = "查询app下载记录列表")
    @PreAuthorize("@ss.hasPermi('tencreat:record:list')")
    @PostMapping("/list")
        public HttpResult<IPage<AppDownloadRecord>> list(@RequestBody AppDownloadRecord appDownloadRecord) {
        IPage<AppDownloadRecord> iPage = generatePage(appDownloadRecord);
        return HttpResult.ok(appDownloadRecordService.page(iPage, appDownloadRecord));
    }
    
    /**
     * 导出app下载记录列表
     */
    @ApiOperation(value = "导出app下载记录列表")
    @PreAuthorize("@ss.hasPermi('tencreat:record:export')")
    @Log(title = "app下载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(@RequestBody AppDownloadRecord appDownloadRecord) {
        List<AppDownloadRecord> list = appDownloadRecordService.page(getMaxPage(), appDownloadRecord).getRecords();
        ExcelUtil<AppDownloadRecord> util = new ExcelUtil<>(AppDownloadRecord. class);
        return util.exportExcel(list, "app下载记录");
    }

    /**
     * 获取app下载记录详细信息
     */
    @ApiOperation(value = "获取app下载记录详细信息")
    @PreAuthorize("@ss.hasPermi('tencreat:record:query')")
    @GetMapping(value = "/getInfo/{id}")
    public HttpResult<AppDownloadRecord> getInfo(@PathVariable("id") Long id) {
        return HttpResult.ok(appDownloadRecordService.getById(id));
    }

    /**
     * 新增app下载记录
     */
    @ApiOperation(value = "新增app下载记录")
    @PreAuthorize("@ss.hasPermi('tencreat:record:add')")
    @Log(title = "app下载记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody @Validated AppDownloadRecord appDownloadRecord) {
        return to(appDownloadRecordService.save(appDownloadRecord));
    }

    /**
     * 修改app下载记录
     */
    @ApiOperation(value = "修改app下载记录")
    @PreAuthorize("@ss.hasPermi('tencreat:record:edit')")
    @Log(title = "app下载记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody @Validated AppDownloadRecord appDownloadRecord) {
        return to(appDownloadRecordService.updateById(appDownloadRecord));
    }

    /**
     * 删除app下载记录
     */
    @ApiOperation(value = "删除app下载记录")
    @PreAuthorize("@ss.hasPermi('tencreat:record:remove')")
    @Log(title = "app下载记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody List<Long> ids) {
        return to(appDownloadRecordService.removeByIds(ids));
    }
}
